#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using EstateNuke.Data;
using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using System.Linq;

#endregion

namespace EstateNuke.BusinessSystem.Controls.EstateControls
{
    public partial class RoomGroupViewControl : UserControl
    {
        private Entrance _currentEntrance;
        private Floor _currentFloor;
        private RoomOperationType _roomOperationType;
        public RoomGroupViewControl(Entrance entrance, Floor floor, RoomOperationType type)
        {
            _currentEntrance = entrance;
            _currentFloor = floor;
            _roomOperationType = type;

            InitializeComponent();
            BindRoomGroup();
        }

        private void BindRoomGroup()
        {
            this.Width = (Constant.ViewRoomWidth + 4) * _currentEntrance.RoomsNumberPerFloor;
            this.Height = Constant.ViewRoomHeight + 4;

            if (_roomOperationType == RoomOperationType.RoomView || _roomOperationType == RoomOperationType.RoomEdit || _roomOperationType == RoomOperationType.RoomSales)
            {
                var lstRoom = _currentEntrance.AllRooms.Where(r => r.Floor == _currentFloor).OrderBy(c=>c.Name).ToList();

                foreach (var room in lstRoom)
                {
                    if (_roomOperationType == RoomOperationType.RoomView || _roomOperationType == RoomOperationType.RoomSales)
                    {
                        if (!room.IsDeleted)
                        {
                            RoomViewControl roomView = new RoomViewControl(room, _roomOperationType);
                            flpRoomContainer.Controls.Add(roomView);
                        }
                        else
                        {
                            EmptyRoomControl roomView = new EmptyRoomControl();
                            flpRoomContainer.Controls.Add(roomView);
                        }
                    }
                    else
                    {
                        RoomEditControl roomView = new RoomEditControl(room);
                        flpRoomContainer.Controls.Add(roomView);
                    }
                }
            }
            else
            {
                var lstProperty = _currentEntrance.AllProperties.Where(r => r.Floor == _currentFloor).OrderBy(c => c.Name).ToList();

                foreach (var property in lstProperty)
                {
                    if (_roomOperationType == RoomOperationType.PropertyView || _roomOperationType == RoomOperationType.PropertySales)
                    {
                        if (!property.IsDeleted)
                        {
                            PropertyViewControl propertyView = new PropertyViewControl(property, _roomOperationType);
                            flpRoomContainer.Controls.Add(propertyView);
                        }
                        //else
                        //{
                        //    EmptyRoomControl propertyView = new EmptyRoomControl();
                        //    flpRoomContainer.Controls.Add(propertyView);
                        //}
                    }
                    else
                    {
                        PropertyEditControl propertyView = new PropertyEditControl(property);
                        flpRoomContainer.Controls.Add(propertyView);
                    }
                }
            }
        }
    }
}